﻿using System.Drawing;
using System.Windows.Forms;
using WinForm.Properties;

namespace WinForm.Common
{
    public partial class FrmMessageBox : Form
    {
        public FrmMessageBox(MessageBoxStyle messageBoxStyle, string msg)
        {
            InitializeComponent();

            if (messageBoxStyle == MessageBoxStyle.info)
            {
                picICO.Image = Resources.info;
                Text = "提示";
                panel1.Visible = true;
                panel2.Visible = false;
            }
            else if (messageBoxStyle == MessageBoxStyle.question)
            {
                picICO.Image = Resources.question;
                Text = "询问";
                panel1.Visible = false;
                panel2.Visible = true;
            }
            else if (messageBoxStyle == MessageBoxStyle.error)
            {
                picICO.Image = Resources.error;
                Text = "错误";
                panel1.Visible = true;
                panel2.Visible = false;
            }

            labInfo.Text = msg;

            SizeF size = TextRenderer.MeasureText(msg, new Font("宋体", 14, FontStyle.Regular));

            var TempWidth = (int) size.Width;
            if (TempWidth <= 249)
            {
                return;
            }

            Width = (int) size.Width + 150;
            panel1.Width = TempWidth - 20;
            panel2.Width = TempWidth - 20;
            btnYes.Width = TempWidth/2 - 20;
            btnNo.Width = TempWidth/2 - 20;
        }
    }

    public enum MessageBoxStyle
    {
        info = 0,
        question = 1,
        error = 2
    };

    public enum MessageBoxResult
    {
        None,
        OK,
        Cancel,
        Abort,
        Retry,
        Ignore,
        Yes,
        No
    }
}